<?php
$objXajax->registerFunction("cusfrmreportproduct_load");

function cusfrmreportproduct_load($dateFrom,$dateTo){     

    global $lang;
    $objResponse = new xajaxResponse();// dong luon luon co khi goi ham ajax
    $arrData = cusfrmreportproduct_createArray($dateFrom,$dateTo);
    $oTbs = new clsTinyButStrong();
    $oTbs->LoadTemplate('templates/'.$lang.'/customer/cus_reportproduct_grid.html');
    $oTbs->MergeBlock('blk_data', $arrData); 
    $oTbs->Show(TBS_NOTHING);  
    $objResponse->addAssign('cusfrmreportproduct_divGrid', 'innerHTML', $oTbs->Source);
    $objResponse->addScriptCall("dataTableObj.CreatDataTable('cusfrmreportproduct_tbl',true);");  
    $objResponse->addScript('changeWaiting(1);');                     
    return $objResponse->getXML(); // dong luon luon co khi goi ham ajax   
}

function cusfrmreportproduct_createArray($dateFrom,$dateTo){
    global $objDbUpdate,$tbl_postfix;
    $sqlGroup='';
    $sql = "select sum(num) as num ,p.name_vi as name from cus_product$tbl_postfix as p
left join cus_history_product$tbl_postfix as h on p.id = h.product_id and
datediff(h.date_created,'$dateFrom')>=0 and datediff(h.date_created,'$dateTo')<=0 where p.id <> p.parent_id  group by p.id order by p.name_vi";
//echo $sql; die();
    $arr = array();
    try{
        $arr = $objDbUpdate->GetArray($sql);
        
    }
    catch(Exception $e){
        $arr = array();
    } 
    return  $arr  ;
} 


# end region process data
?>
